package com.dungnt.vtime.event;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;

import com.dungnt.vtime.R;

public class VTSetEventActivity extends Activity implements OnClickListener {

	private static final int DATE_PICKER_ID = 1;
	private EditText edtTitle, edtContent, edtTime, edtFolder;
	private Button btnCancel, btnConfirm;
	private int year, day, month;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setevent_activity);
		edtContent = (EditText) findViewById(R.id.edtContent);
		edtTime = (EditText) findViewById(R.id.edtTime);
		edtTitle = (EditText) findViewById(R.id.edtTitle);
		edtFolder = (EditText) findViewById(R.id.edtFolder);
		btnCancel = (Button) findViewById(R.id.setevent_cancel);
		btnConfirm = (Button) findViewById(R.id.setevent_confirm);
		btnCancel.setOnClickListener(this);
		btnConfirm.setOnClickListener(this);
		edtTime.setOnClickListener(this);
		final Calendar c = Calendar.getInstance();
		year = c.get(Calendar.YEAR);
		month = c.get(Calendar.MONTH);
		day = c.get(Calendar.DAY_OF_MONTH);
	}

	@Override
	@Deprecated
	protected Dialog onCreateDialog(int id, Bundle args) {
		// TODO Auto-generated method stub
		switch (id) {
		case DATE_PICKER_ID:
			return new DatePickerDialog(this, pickerListener, year, month, day);
		default:
			break;
		}
		return null;
	}

	private DatePickerDialog.OnDateSetListener pickerListener = new DatePickerDialog.OnDateSetListener() {

		// when dialog box is closed, below method will be called.
		@Override
		public void onDateSet(DatePicker view, int selectedYear,
				int selectedMonth, int selectedDay) {

			year = selectedYear;
			month = selectedMonth;
			day = selectedDay;

			// Show selected date
			edtTime.setText(new StringBuilder().append(month + 1).append("-")
					.append(day).append("-").append(year).append(" "));

		}
	};

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v == btnCancel) {
			finish();
		} else if (v == btnConfirm) {

			finish();
		} else if (v == edtTime) {
			Log.d("DungNT","Time is clicked");
			showDialog(DATE_PICKER_ID);
		}
	}
}
